package com.wangwei.jvm.jmm;


import com.wangwei.ObjectSizeAgent;

/**
 * 计算对象大小
 */
public class T03_SizeOfAnObject {
    public static void main(String[] args) {


        //new Object() 大小计算
        //markword 8
        //class pointer 4(默认是开启指针的压缩)
        //Padding 4
        System.out.println(ObjectSizeAgent.sizeOf(new Object()));


        //new int[]{} 大小计算
        //markword 8
        //class pointer默认开启指针压缩(-XX:+UseCompressedClassPointers):4,关闭指针压缩(-XX:-UseCompressedClassPointers):8
        //数组长度
        System.out.println(ObjectSizeAgent.sizeOf(new int[]{}));
        //new P() 大小计算
        //markword 8
        //关闭指针压缩(-XX:-UseCompressedClassPointers) 8
        //
        System.out.println(ObjectSizeAgent.sizeOf(new P()));
    }

    private static class P {
        //8 _markword
        //4 _oop指针
        int id;         //4
        String name;    //4
        int age;        //4

        byte b1;        //1
        byte b2;        //1

        Object o;       //4
        byte b3;        //1

    }
}
